package com.harmontronics.hanma.paas.paas.service;

import com.harmontronics.hanma.paas.paas.common.MosResponse;
import com.harmontronics.hanma.paas.paas.domain.organization.entity.OrgTree;
import com.harmontronics.hanma.paas.paas.domain.organization.entity.OrgUserExport;
import com.harmontronics.hanma.paas.paas.domain.organization.entity.SsoOrgTreeDtoResult;
import com.harmontronics.hanma.paas.paas.domain.organization.service.IHmUserOrgService;
import com.harmontronics.hanma.paas.paas.domain.organization.service.MosService;
import com.harmontronics.hanma.paas.paas.utils.MyBeanUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

@Service("hmUserOrgMosAppService")
@ConditionalOnProperty(prefix = "mos.oss",name="enabled",havingValue = "true")
public class HmUserOrgMosAppService implements IHmUserOrgService {

    @Autowired
    private MosService mosService;

    @Override
    public boolean selectUserWithOrgIds(List<Long> orgIds) {
        String tmpIds = orgIds.stream().map(id -> id.toString()).collect(Collectors.joining(","));
        Boolean result = mosService.existUserByOrgIds(tmpIds);

        return result;
    }

    @Override
    public List<OrgTree> selectOrgWithUserId(Long userId) {
        List<OrgTree> orgTreeList = new ArrayList<>();
        MosResponse<List<SsoOrgTreeDtoResult>> response = mosService.getOrgByUserId(userId);
        if(response.isOk()){
            List<SsoOrgTreeDtoResult> resultList = response.getData();
            orgTreeList = MyBeanUtils.batchTransform(OrgTree.class,resultList);
        }
        return orgTreeList;
    }

    @Override
    public void updateUserOrgById(Long userId, List<Long> orgIds) {

    }

    @Override
    public void moveOrgWithUserId(List<Long> userIds, Long srcId, Long orgId) {

    }

    @Override
    public List<OrgUserExport> selectExportUserWithOrgId(long orgId, String name, String username,
            String mobile, Integer status, String email) {
        return null;
    }
}
